﻿<navigation:PageView x:Class="Corina.Cydee.Apphub.Views.Bases.UserlevelView"
                     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                     xmlns:controls="clr-namespace:Corina.Controls.Silverlight;assembly=Corina.Controls.Silverlight"
                     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                     xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                     xmlns:localViewmodel="clr-namespace:Corina.Cydee.Apphub.Viewmodels"
                     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                     xmlns:navigation="clr-namespace:Corina.Cydee.Apphub.Base"
                     xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
                     xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
                     Title="用户级别"
                     d:DesignHeight="480"
                     d:DesignWidth="640"
                     mc:Ignorable="d">
    <navigation:PageView.DataContext>
        <localViewmodel:UserLevelViewmodel />
    </navigation:PageView.DataContext>
    <Grid x:Name="LayoutRoot">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>

            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="300" />
                    <ColumnDefinition />
                    <ColumnDefinition Width="auto" />
                </Grid.ColumnDefinitions>
                <TextBlock VerticalAlignment="Center"
                           Style="{StaticResource ControlLabelStyle}"
                           Text="关键字：" />

                <TextBox Grid.Column="1" Text="{Binding Keywords, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

                <Button Grid.Column="3"
                        Width="60"
                        Command="{Binding InsertCommand}"
                        Content="新增" />
            </Grid>

            <toolkit:BusyIndicator Grid.Row="1"
                                   BusyContent="正在加载数据，请稍后..."
                                   IsBusy="{Binding IsBusy}">
                <sdk:DataGrid Margin="0,12,0,0"
                              AutoGenerateColumns="False"
                              ColumnWidth="*"
                              IsReadOnly="True"
                              ItemsSource="{Binding DisplayCollection}">
                    <sdk:DataGrid.Columns>
                        <sdk:DataGridTextColumn Binding="{Binding Title}" Header="标题" />
                        <sdk:DataGridTextColumn Binding="{Binding Level}" Header="级别" />
                        <sdk:DataGridTextColumn Binding="{Binding Description}" Header="描述" />
                        <sdk:DataGridTemplateColumn Header="是否可用">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Button Style="{StaticResource CheckButtonStyle}" Visibility="{Binding IsAvailable, Converter={StaticResource BooleanToVisibilityConverter}}">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.ChangeCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </Button>
                                        <Button Style="{StaticResource CrossButtonStyle}" Visibility="{Binding IsAvailable, Converter={StaticResource BooleanToVisibilityInverseConverter}}">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.ChangeCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </Button>
                                    </Grid>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                        <sdk:DataGridTemplateColumn Header="操作">
                            <sdk:DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <StackPanel VerticalAlignment="Center" Orientation="Horizontal">

                                        <HyperlinkButton Content="编辑">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                        <HyperlinkButton Margin="12,0" Content="删除">
                                            <i:Interaction.Triggers>
                                                <i:EventTrigger EventName="Click">
                                                    <i:InvokeCommandAction Command="{Binding Path=DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=navigation:PageView}}" CommandParameter="{Binding Id}" />
                                                </i:EventTrigger>
                                            </i:Interaction.Triggers>
                                        </HyperlinkButton>
                                    </StackPanel>
                                </DataTemplate>
                            </sdk:DataGridTemplateColumn.CellTemplate>
                        </sdk:DataGridTemplateColumn>
                    </sdk:DataGrid.Columns>
                </sdk:DataGrid>
            </toolkit:BusyIndicator>
        </Grid>

        <controls:PromptDialog Title="{Binding Operation,
                                               Converter={StaticResource EnumTranslationConverter},
                                               ConverterParameter=ENTITYOPERATION}"
                               CloseCommand="{Binding CancelCommand}"
                               Padding="50"
                               Visibility="{Binding ShowUpdate,
                                                    Converter={StaticResource BooleanToVisibilityConverter}}"
                               WindowHeight="320"
                               WindowWidth="400">
            <Grid Margin="12" HorizontalAlignment="Stretch">
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <StackPanel Width="300">
                    <TextBlock Text="标题" />
                    <TextBox Text="{Binding UpdateEntity.Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    <StackPanel Visibility="{Binding Operation, Converter={StaticResource EuqalsToVisibilityConverter}, ConverterParameter=Insert}">
                        <TextBlock Margin="0,12,0,0" Text="级别" />
                        <TextBox VerticalContentAlignment="Stretch" Text="{Binding UpdateEntity.Level, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>
                    <TextBlock Margin="0,12,0,0" Text="描述" />
                    <TextBox VerticalContentAlignment="Stretch"
                             AcceptsReturn="True"
                             Text="{Binding UpdateEntity.Description,
                                            Mode=TwoWay,
                                            UpdateSourceTrigger=PropertyChanged}"
                             TextWrapping="Wrap" />
                    <CheckBox Margin="0,12,0,0"
                              Content="是否可用？"
                              IsChecked="{Binding UpdateEntity.IsAvailable,
                                                  Mode=TwoWay}" />
                </StackPanel>

                <StackPanel Grid.Row="1"
                            HorizontalAlignment="Right"
                            Orientation="Horizontal">
                    <Button Width="60"
                            Margin="12,0"
                            Command="{Binding SubmitCommand}"
                            Content="提交" />
                    <Button Width="60"
                            Margin="12,0"
                            Command="{Binding CancelCommand}"
                            Content="取消" />
                </StackPanel>
            </Grid>
        </controls:PromptDialog>

    </Grid>
</navigation:PageView>
